<?php
class BackupController extends Controller{
	public function __init(){}
	public function index(){
		$this->display();
	}

	// 备份数据
	public function backup(){
		$result = Backup::backup(
	            array(
	                "size" => 200,//每个卷多大,单位是KB
	                "dir" => C("DB_BACKUP")  . date("Ymdhis")
	            )
	        );
	        if ($result['status'] == 'success') {
	            $this->success($result['message'], U('index'));
	        } else {
	            $this->success($result['message'], $result['url'], 0.2);
	        }
	}

	//备份列表
	public function backupList(){
		$dirs = Dir::tree('Backup');
		$this->assign('dirs',$dirs);
		$this->display();
	}
	
	//删除备份
	public function del(){
		$dir = C("DB_BACKUP").Q("dir");
		if(Dir::del($dir)){
			$this->success('删除成功');
		}else{
			$this->error('删除失败');
		}
	}

	//数据还原
	public function recovery(){
		$dir = C("DB_BACKUP") . Q("dir");
	        $result = Backup::recovery(array('dir' => $dir));
	        if ($result['status'] == 'success') {
	            $this->success($result['message'], U('index'));
	        } else {
	            $this->success($result['message'], $result['url'], 0.2);
	        }

	}

}

?>